package com.yd.app.mapper;

import com.yd.app.mapper.provider.GTypeOneProvider;
import com.yd.domain.business.*;
import com.yd.domain.searchParam.GTypeOneParam;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: zy
 * @Desc: 商品分类导航
 * @Date:  2018/4/28
 * @Param
 */
@Repository
public interface GoodTypeMapper {
    /**
     * @Author: zy
     * @Desc:
     * @Date:  2018/4/28
     * @Param
     */
    @Select("select * from business_gstyle where ifUse=1 AND pId=#{pId} order by sort")
    List<GStyle> getGStyleList(@Param("pId") String pId);

    /**
     * @Author: sxh
     * @Desc: 获取商品类型列表
     * @Date:  2018/4/12
     * @Param
     */
    @Select("select * from business_gType where ifUse=1 AND pId=#{pId} ")
    List<GType> getGTypeList(@Param("pId") String pId);

    @Select("select * from business_gtype_one order by sort")
    List<GTypeOne> getTypeOne();

    @Select("select * from business_gstyle where ifUse=1 AND pId=#{pId} order by sort")
    List<GStyleWithGoods> getGStyleWithGoodsList(@Param("pId") String pId);
    /**
     * @Author: zy
     * @Desc: 新增
     * @Date:  2018/5/2
     * @Param
     */
    @Insert("INSERT INTO business_gtype_one (id,title,sort,iconUrl )" +
            " VALUES(#{o.id},#{o.title},#{o.sort},#{o.iconUrl})")
    void addGTypeOne(@Param("o")GTypeOne o);
    /**
     * @Author: zy
     * @Desc: 修改
     * @Date:  2018/5/2
     * @Param
     */
    @Update("UPDATE business_gtype_one set title=#{o.title},sort=#{o.sort},iconUrl=#{o.iconUrl} where id=#{o.id}")
    void updateTypeOne(@Param("o")GTypeOne o);
    /**
     * @Author: zy
     * @Desc: 删除
     * @Date:  2018/5/2
     * @Param
     */
    @Delete("DELETE from business_gtype_one where id=#{id}")
    void deleteTypeOne(@Param("id") String id);
    /**
     * @Author: zy
     * @Desc: 分页查询
     * @Date:  2018/5/2
     * @Param
     */
    @SelectProvider(method = "searchGTypeOneList",type= GTypeOneProvider.class)
    List<GTypeOne> searchGTypeOneList(@Param("gTypeOneParam") GTypeOneParam gTypeOneParam, @Param("startRow") int startRow, @Param("pageSize") int pageSize);
    /**
     * @Author: zy
     * @Desc:查询数量
     * @Date:  2018/3/7
     */
    @SelectProvider(method = "searchGTypeOneCount",type= GTypeOneProvider.class)
    int searchGTypeOneCount(@Param("gTypeOneParam") GTypeOneParam gTypeOneParam);
    @Select("select * from business_gtype_one where id=#{id}")
    GTypeOne getById(@Param("id") String id);
    @Select("SELECT g.* from business_gtype g WHERE pId=(SELECT t.pId from business_gtype t WHERE t.id =#{type})")
    List<GType> getTypeList(@Param("type") String type);
    @Select("SELECT g.* from business_gstyle g WHERE pId=(SELECT t.pId from business_gstyle t WHERE t.id =#{gstyle})")
    List<GStyle> getStyleList(@Param("gstyle") String gstyle);
    /*********************************************品型增删改查******************************************/
    @Delete("DELETE from business_pinxing where id=#{id}")
    void deletePX(@Param("id") String id);
    @Update("UPDATE business_pinxing set title=#{o.title},sort=#{o.sort},pId=#{o.pId} where id=#{o.id}")
    void updatePX(@Param("o") PinXing o);
    @Insert("INSERT INTO business_pinxing (id,title,sort,pId )" +
            " VALUES(#{o.id},#{o.title},#{o.sort},#{o.pId})")
    void addPinXing(@Param("o") PinXing o);
    @Select("select * from business_pinxing where  pId=#{pId} ")
    List<PinXing> getPListByPId(@Param("pId")String pId);

    @Select("select * from business_gtype_one where id in (${ids}) ")
    List<GTypeOne> getListByIds(@Param("ids") String ids);
}
